﻿#region | Copyright © Siriwat Suananpornpanit 2556 |

/*
	##########################################################################
		Software Generator Code For Hashtable From Table Name => APPLICATION
		Author By : Siriwat Suananpornpanit
		DateTime : 2556/08/22 11:14:27
	##########################################################################
	*/

#endregion

#region Class | Imports |

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using DataAccess.DBConnections;
using DataAccess.Interface;
using DataAccess.ProxyConnections;
using Oracle.DataAccess.Client;
using Microsoft.VisualBasic;

#endregion

namespace DataAccess.Dal
{
    internal class ApplicationDal
        //: IResponsible<Prop.Application>
    {

        /* for DataBase Connection */

        private static DBConnectionsEngine dbEngine;

        private static OracleConnection Conn;

        private static Hashtable hashtable;


        private static ApplicationDal _dal;

        private System.String sql = "";


        public static ApplicationDal GetInstance()
        {
            /* for Init */

            dbEngine = new DBConnectionsEngine();

            Conn = new DatabaseProxy().GetAuthConnection();

            _dal = new ApplicationDal();

            return _dal;
        }

        public IEnumerable<Prop.Application> Select(Prop.Application obj)
        {
            IEnumerable<Prop.Application> entities = new List<Prop.Application>();
            try
            {
                System.Text.StringBuilder concast = new System.Text.StringBuilder();

                concast.Append(" WHERE 1=1 ");

                hashtable = new Hashtable();

                if (obj != null)
                {
                    if (!String.IsNullOrEmpty(obj.COMPANY_CODE))
                    {
                        concast.Append(" AND COMPANY_CODE=:COMPANY_CODE ");
                        hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                    }

                    if (!String.IsNullOrEmpty(obj.PRIVATE_FLAG))
                    {
                        concast.Append(" AND PRIVATE_FLAG=:PRIVATE_FLAG ");
                        hashtable.Add(":PRIVATE_FLAG", obj.PRIVATE_FLAG);
                    }

                    if (!String.IsNullOrEmpty(obj.MC_FLAG))
                    {
                        concast.Append(" AND MC_FLAG=:MC_FLAG ");
                        hashtable.Add(":MC_FLAG", obj.MC_FLAG);
                    }

                    if (!String.IsNullOrEmpty(obj.BUYER_FLAG))
                    {
                        concast.Append(" AND BUYER_FLAG=:BUYER_FLAG ");
                        hashtable.Add(":BUYER_FLAG", obj.BUYER_FLAG);
                    }

                    if (!String.IsNullOrEmpty(obj.NT_FLAG))
                    {
                        concast.Append(" AND NT_FLAG=:NT_FLAG ");
                        hashtable.Add(":NT_FLAG", obj.NT_FLAG);
                    }

                    if (!String.IsNullOrEmpty(obj.REMARK))
                    {
                        concast.Append(" AND REMARK=:REMARK ");
                        hashtable.Add(":REMARK", obj.REMARK);
                    }

                    if (!String.IsNullOrEmpty(obj.APPLNO))
                    {
                        concast.Append(" AND APPLNO=:APPLNO ");
                        hashtable.Add(":APPLNO", obj.APPLNO);
                    }

                    if (!String.IsNullOrEmpty(obj.APPLNAME))
                    {
                        concast.Append(" AND APPLNAME=:APPLNAME ");
                        hashtable.Add(":APPLNAME", obj.APPLNAME);
                    }

                    if (!String.IsNullOrEmpty(obj.DESCRIPTION))
                    {
                        concast.Append(" AND DESCRIPTION=:DESCRIPTION ");
                        hashtable.Add(":DESCRIPTION", obj.DESCRIPTION);
                    }

                    if (!Information.IsDate(obj.CRDATE))
                    {
                        concast.Append(" AND CRDATE=:CRDATE ");
                        hashtable.Add(":CRDATE", obj.CRDATE);
                    }

                    if (!String.IsNullOrEmpty(obj.CRBY))
                    {
                        concast.Append(" AND CRBY=:CRBY ");
                        hashtable.Add(":CRBY", obj.CRBY);
                    }

                    if (!Information.IsNumeric(obj.UPDDATE))
                    {
                        concast.Append(" AND UPDDATE=:UPDDATE ");
                        hashtable.Add(":UPDDATE", obj.UPDDATE);
                    }

                    if (!String.IsNullOrEmpty(obj.UPDBY))
                    {
                        concast.Append(" AND UPDBY=:UPDBY ");
                        hashtable.Add(":UPDBY", obj.UPDBY);
                    }

                    if (!String.IsNullOrEmpty(obj.URL))
                    {
                        concast.Append(" AND URL=:URL ");
                        hashtable.Add(":URL", obj.URL);
                    }

                    if (!Information.IsNothing(obj.PDAFLAG))
                    {
                        concast.Append(" AND PDAFLAG=:PDAFLAG ");
                        hashtable.Add(":PDAFLAG", obj.PDAFLAG);
                    }

                    if (!String.IsNullOrEmpty(obj.MOBILEURL))
                    {
                        concast.Append(" AND MOBILEURL=:MOBILEURL ");
                        hashtable.Add(":MOBILEURL", obj.MOBILEURL);
                    }

                    if (!String.IsNullOrEmpty(obj.STATUS))
                    {
                        concast.Append(" AND STATUS=:STATUS ");
                        hashtable.Add(":STATUS", obj.STATUS);
                    }

                }
                sql = System.String.Format(@" SELECT COMPANY_CODE ,PRIVATE_FLAG ,MC_FLAG ,BUYER_FLAG ,NT_FLAG ,REMARK ,APPLNO ,APPLNAME ,DESCRIPTION ,CRDATE ,CRBY ,UPDDATE ,UPDBY ,URL ,PDAFLAG ,MOBILEURL ,STATUS  FROM APPLICATION");

                sql = sql + concast.ToString();

                entities = dbEngine.ToList<Prop.Application>(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                entities = null;
            }
            return entities;
        }

        public bool Add(Prop.Application obj)
        {
            Boolean result = false;
            try
            {
                sql = System.String.Format(@" INSERT INTO APPLICATION(COMPANY_CODE ,PRIVATE_FLAG ,MC_FLAG ,BUYER_FLAG ,NT_FLAG ,REMARK ,APPLNO ,APPLNAME ,DESCRIPTION ,CRDATE ,CRBY ,UPDDATE ,UPDBY ,URL ,PDAFLAG ,MOBILEURL ,STATUS )
					VALUES(:COMPANY_CODE ,:PRIVATE_FLAG ,:MC_FLAG ,:BUYER_FLAG ,:NT_FLAG ,:REMARK ,:APPLNO ,:APPLNAME ,:DESCRIPTION ,:CRDATE ,:CRBY ,:UPDDATE ,:UPDBY ,:URL ,:PDAFLAG ,:MOBILEURL ,:STATUS ");

                hashtable = new Hashtable();
                hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                hashtable.Add(":PRIVATE_FLAG", obj.PRIVATE_FLAG);
                hashtable.Add(":MC_FLAG", obj.MC_FLAG);
                hashtable.Add(":BUYER_FLAG", obj.BUYER_FLAG);
                hashtable.Add(":NT_FLAG", obj.NT_FLAG);
                hashtable.Add(":REMARK", obj.REMARK);
                hashtable.Add(":APPLNO", obj.APPLNO);
                hashtable.Add(":APPLNAME", obj.APPLNAME);
                hashtable.Add(":DESCRIPTION", obj.DESCRIPTION);
                hashtable.Add(":CRDATE", obj.CRDATE);
                hashtable.Add(":CRBY", obj.CRBY);
                hashtable.Add(":UPDDATE", obj.UPDDATE);
                hashtable.Add(":UPDBY", obj.UPDBY);
                hashtable.Add(":URL", obj.URL);
                hashtable.Add(":PDAFLAG", obj.PDAFLAG);
                hashtable.Add(":MOBILEURL", obj.MOBILEURL);
                hashtable.Add(":STATUS", obj.STATUS);
                dbEngine.ExecuteNonQuery(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                result = true;
            }
            return result;
        }

        public bool Update(Prop.Application obj)
        {
            Boolean result = false;
            try
            {
                sql = System.String.Format(@" UPDATE APPLICATION
					SET
					COMPANY_CODE=:COMPANY_CODE,
					PRIVATE_FLAG=:PRIVATE_FLAG,
					MC_FLAG=:MC_FLAG,
					BUYER_FLAG=:BUYER_FLAG,
					NT_FLAG=:NT_FLAG,
					REMARK=:REMARK,
					APPLNO=:APPLNO,
					APPLNAME=:APPLNAME,
					DESCRIPTION=:DESCRIPTION,
					CRDATE=:CRDATE,
					CRBY=:CRBY,
					UPDDATE=:UPDDATE,
					UPDBY=:UPDBY,
					URL=:URL,
					PDAFLAG=:PDAFLAG,
					MOBILEURL=:MOBILEURL,
					STATUS=:STATUS
                    WHERE COMPANY_CODE=:COMPANY_CODE AND APPLNO=:APPLNO
                    ");

                hashtable = new Hashtable();
                hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                hashtable.Add(":PRIVATE_FLAG", obj.PRIVATE_FLAG);
                hashtable.Add(":MC_FLAG", obj.MC_FLAG);
                hashtable.Add(":BUYER_FLAG", obj.BUYER_FLAG);
                hashtable.Add(":NT_FLAG", obj.NT_FLAG);
                hashtable.Add(":REMARK", obj.REMARK);
                hashtable.Add(":APPLNO", obj.APPLNO);
                hashtable.Add(":APPLNAME", obj.APPLNAME);
                hashtable.Add(":DESCRIPTION", obj.DESCRIPTION);
                hashtable.Add(":CRDATE", obj.CRDATE);
                hashtable.Add(":CRBY", obj.CRBY);
                hashtable.Add(":UPDDATE", obj.UPDDATE);
                hashtable.Add(":UPDBY", obj.UPDBY);
                hashtable.Add(":URL", obj.URL);
                hashtable.Add(":PDAFLAG", obj.PDAFLAG);
                hashtable.Add(":MOBILEURL", obj.MOBILEURL);
                hashtable.Add(":STATUS", obj.STATUS);

                dbEngine.ExecuteNonQuery(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                result = true;
            }
            return result;
        }

        public bool Delete(Prop.Application obj)
        {
            Boolean result = false;
            try
            {

                System.Text.StringBuilder concast = new System.Text.StringBuilder();

                concast.Append(" WHERE 1=1 ");

                hashtable = new Hashtable();

                if (obj != null)
                {
                    if (!String.IsNullOrEmpty(obj.COMPANY_CODE))
                    {
                        concast.Append(" AND COMPANY_CODE=:COMPANY_CODE ");
                        hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                    }

                    if (!String.IsNullOrEmpty(obj.PRIVATE_FLAG))
                    {
                        concast.Append(" AND PRIVATE_FLAG=:PRIVATE_FLAG ");
                        hashtable.Add(":PRIVATE_FLAG", obj.PRIVATE_FLAG);
                    }

                    if (!String.IsNullOrEmpty(obj.MC_FLAG))
                    {
                        concast.Append(" AND MC_FLAG=:MC_FLAG ");
                        hashtable.Add(":MC_FLAG", obj.MC_FLAG);
                    }

                    if (!String.IsNullOrEmpty(obj.BUYER_FLAG))
                    {
                        concast.Append(" AND BUYER_FLAG=:BUYER_FLAG ");
                        hashtable.Add(":BUYER_FLAG", obj.BUYER_FLAG);
                    }

                    if (!String.IsNullOrEmpty(obj.NT_FLAG))
                    {
                        concast.Append(" AND NT_FLAG=:NT_FLAG ");
                        hashtable.Add(":NT_FLAG", obj.NT_FLAG);
                    }

                    if (!String.IsNullOrEmpty(obj.REMARK))
                    {
                        concast.Append(" AND REMARK=:REMARK ");
                        hashtable.Add(":REMARK", obj.REMARK);
                    }

                    if (!String.IsNullOrEmpty(obj.APPLNO))
                    {
                        concast.Append(" AND APPLNO=:APPLNO ");
                        hashtable.Add(":APPLNO", obj.APPLNO);
                    }

                    if (!String.IsNullOrEmpty(obj.APPLNAME))
                    {
                        concast.Append(" AND APPLNAME=:APPLNAME ");
                        hashtable.Add(":APPLNAME", obj.APPLNAME);
                    }

                    if (!String.IsNullOrEmpty(obj.DESCRIPTION))
                    {
                        concast.Append(" AND DESCRIPTION=:DESCRIPTION ");
                        hashtable.Add(":DESCRIPTION", obj.DESCRIPTION);
                    }

                    if (!Information.IsDate(obj.CRDATE))
                    {
                        concast.Append(" AND CRDATE=:CRDATE ");
                        hashtable.Add(":CRDATE", obj.CRDATE);
                    }

                    if (!String.IsNullOrEmpty(obj.CRBY))
                    {
                        concast.Append(" AND CRBY=:CRBY ");
                        hashtable.Add(":CRBY", obj.CRBY);
                    }

                    if (!Information.IsDate(obj.UPDDATE))
                    {
                        concast.Append(" AND UPDDATE=:UPDDATE ");
                        hashtable.Add(":UPDDATE", obj.UPDDATE);
                    }

                    if (!String.IsNullOrEmpty(obj.UPDBY))
                    {
                        concast.Append(" AND UPDBY=:UPDBY ");
                        hashtable.Add(":UPDBY", obj.UPDBY);
                    }

                    if (!String.IsNullOrEmpty(obj.URL))
                    {
                        concast.Append(" AND URL=:URL ");
                        hashtable.Add(":URL", obj.URL);
                    }

                    if (!Information.IsNothing(obj.PDAFLAG))
                    {
                        concast.Append(" AND PDAFLAG=:PDAFLAG ");
                        hashtable.Add(":PDAFLAG", obj.PDAFLAG);
                    }

                    if (!String.IsNullOrEmpty(obj.MOBILEURL))
                    {
                        concast.Append(" AND MOBILEURL=:MOBILEURL ");
                        hashtable.Add(":MOBILEURL", obj.MOBILEURL);
                    }

                    if (!String.IsNullOrEmpty(obj.STATUS))
                    {
                        concast.Append(" AND STATUS=:STATUS ");
                        hashtable.Add(":STATUS", obj.STATUS);
                    }

                }
                sql = System.String.Format(@" DELETE FROM APPLICATION ");

                sql = sql + concast.ToString();

                dbEngine.ExecuteNonQuery(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                result = true;
            }
            return result;
        }

    }
}

/*
##########################################################################
    Free Software License
##########################################################################
*/
